import { defineApplicationConfig } from '@vben/vite-config';

export default defineApplicationConfig({
  overrides: {
    // optimizeDeps: {
    //   include: [
    //     'echarts/core',
    //     'echarts/charts',
    //     'echarts/components',
    //     'echarts/renderers',
    //     'qrcode',
    //     '@iconify/iconify',
    //     'ant-design-vue/es/locale/zh_CN',
    //     'ant-design-vue/es/locale/en_US',
    //     'ant-design-vue/es/locale/ja_JP',
    //     'ant-design-vue/es/locale/zh_TW',
    //     'vxe-pc-ui/lib/language/zh-CN',
    //     'vxe-pc-ui/lib/language/en-US',
    //     'vxe-pc-ui/lib/language/ja-JP',
    //     'vxe-pc-ui/lib/language/zh-TW',
    //   ],
    // },
    css: {
      preprocessorOptions: {
        scss: {
          // 把sass即将弃用的js-api和颜色函数警告去掉
          // silenceDeprecations: ['legacy-js-api', 'color-functions'],
          // 全局导入设计变量
          // additionalData: `@use "@/design/config" as *;@use "@vben/styles/global" as *;`,
        },
      },
    },
    build: {
      // target: 'esnext',
      // cssTarget: 'chrome80',
      rollupOptions: {
        onwarn(warning, warn) {
          // 忽略 PURE 注释位置警告
          if (warning.code === 'INVALID_ANNOTATION' && warning.message.includes('PURE')) {
            return;
          }
          warn(warning);
        },
        output: {
          // 入口文件名
          // entryFileNames: 'assets/entry/[name]-[hash].js',
          // 将大型库分离到独立 chunk
          // manualChunks: {
          //   // Vue 核心库
          //   vue: ['vue', 'vue-router'],
          //   pinia: ['pinia', 'pinia-plugin-persistedstate'],
          //   // UI 组件库 - 分离成多个 chunk 避免单个过大
          //   antd: ['ant-design-vue'],
          //   'antd-icons': ['@ant-design/icons-vue'],
          //   vxe: ['vxe-table', 'vxe-pc-ui', 'vxe-table-plugin-export-xlsx'],
          //   // 大型工具库
          //   echarts: ['echarts'],
          //   // 富文本编辑器 - 这些库通常很大
          //   tinymce: ['tinymce'],
          //   // vditor: ['vditor'],
          //   codemirror: ['codemirror'],
          //   // 流程图库
          //   // logicflow: ['@logicflow/core', '@logicflow/extension'],
          //   // 其他工具库
          //   utils: ['lodash-es', 'dayjs', 'axios'],
          //   qs: ['qs'],
          //   'xe-utils': ['xe-utils'],
          //   excel: ['exceljs', 'xlsx'],
          //   crypto: ['@zxcvbn-ts/core', 'secure-ls'],
          //   canvas: ['html2canvas', 'cropperjs', 'qrcode'],
          // },
        },
      },
    },
    server: {
      https: undefined,
      // Listening on all local IPs
      host: true,
      port: 38061,
      /** 代理设置列表 */
      proxy: {
        '/api': {
          target: 'http://aliyun.sanqing.tech:38062',
          changeOrigin: false, // 更改源
          ws: true,
          // rewrite: (path) => path.replace(new RegExp(`^/api`), ''),
          rewrite: (path) => path,
          // !only https
          // secure: false,
          // !解决页面跳转模式下参数丢失的问题。
          bypass: (req: any, _res: any, _options: any) => {
            req.url = (req as any)?.originalUrl || req.url;
          },
        },
        '/signin-': {
          target: 'http://aliyun.sanqing.tech:38062',
          changeOrigin: false, // 更改源
          ws: true,
          rewrite: (path) => path,
          // !解决页面跳转模式下参数丢失的问题。
          bypass: (req: any, _res: any, _options: any) => {
            req.url = (req as any)?.originalUrl || req.url;
          },
        },
        '/signalr': {
          target: 'http://aliyun.sanqing.tech:38062',
          changeOrigin: false, // 更改源
          ws: true,
          rewrite: (path) => path,
          // !解决页面跳转模式下参数丢失的问题。
          bypass: (req: any, _res: any, _options: any) => {
            req.url = (req as any)?.originalUrl || req.url;
          },
        },
        '/file': {
          target: 'http://aliyun.sanqing.tech:38062',
          changeOrigin: false, // 更改源
          ws: true,
          rewrite: (path) => path,
          // !解决页面跳转模式下参数丢失的问题。
          bypass: (req: any, _res: any, _options: any) => {
            req.url = (req as any)?.originalUrl || req.url;
          },
        },
        '/upload': {
          target: 'http://aliyun.sanqing.tech:38062',
          changeOrigin: false, // 更改源
          ws: true,
          rewrite: (path) => path,
          // !解决页面跳转模式下参数丢失的问题。
          bypass: (req: any, _res: any, _options: any) => {
            req.url = (req as any)?.originalUrl || req.url;
          },
        },
      },
      open: false, // 项目启动后，自动打开
      warmup: {
        // 预热文件
        clientFiles: [
          './index.html',
          // './src/bootstrap.ts',
          './src/{views,components,layouts,router,store,api,adapter}/*',
        ],
      },
    },
  },
});
